package com.cuiweiyou.gimmick;

import java.util.List;

public class MainMaker {
    private static GimmickUI gimmickUI;
    private static GimmickMaster gimmickMaster;

    public static void main(String[] args) {
        gimmickUI = new GimmickUI();
        gimmickMaster = new GimmickMaster(gimmickUI);

        gimmickUI.setOnLoadGimmicksListener(new GimmickUI.OnLoadGimmicksListener() {
            @Override
            public void onLoadGimmicks(String filePath) {
                System.out.println("加载话术");
                gimmickMaster.loadGimmicks(filePath);
            }
        });

        gimmickUI.setOnSaveGimmicksListener(new GimmickUI.OnSaveGimmicksListener() {
            @Override
            public void onSaveGimmicks(String filePath) {
                System.out.println("保存话术");
                gimmickMaster.saveGimmicks(filePath);
            }
        });

        gimmickUI.setOnChattestListener(new GimmickUI.OnChattestListener() {
            @Override
            public void onChattest(List<GimmickBean> gimmicks) {
                //if (null != gimmicks && gimmicks.size() > 0) {
                    ChattestUI chattestUI = new ChattestUI(gimmickUI, gimmicks);
                //}
            }
        });

        gimmickUI.setOnRestLastGimmicksListener(new GimmickUI.OnResetLastGimmicksListener() {
            @Override
            public void onResetLastGimmicks() {
                System.out.println("清除'上一条话术'集合");
                gimmickMaster.clearOthersideGimmicks();
            }
        });

        gimmickUI.setOnInsertGimmickListener(new GimmickUI.OnInsertGimmickListener() {
            @Override
            public void onInsertGimmick(String gimmick) {
                System.out.println("插入一条话术：" + gimmick);
                gimmickMaster.addGimmick(gimmick);
            }
        });

        gimmickUI.setOnSideItemSelectedListener(new GimmickUI.OnSideItemSelectedListener() {
            @Override
            public void onSideItemSelected(String side) {
                System.out.println("话术所属：" + side);
                gimmickMaster.setGimmickSide(side);
            }
        });

        gimmickUI.setOnClearGimmickListViewListener(new GimmickUI.OnClearGimmickListViewListener() {
            @Override
            public void onClearGimmickListView() {
                System.out.println("清空话术列表");
                gimmickMaster.clearGimmicks(); // 直接清空话术列表
            }
        });

        gimmickUI.setOnListViewItemSelectedListener(new GimmickUI.OnListViewItemSelectedListener() {
            @Override
            public void onListViewItemSelected(String element) {
                System.out.println("右键删除对方话术");
                gimmickMaster.removeOtherSideGimmick(
                        element,
                        new GimmickUI.OnListViewItemDeletedListener() {
                            @Override
                            public void onListViewItemDeleted(GimmickBean gimmickBean) {
                                gimmickUI.removeGimmickFromOtherSideListView(gimmickBean);
                            }
                        });
            }
        });

        gimmickUI.setOnTableItemSelectedListener(new GimmickUI.OnTableItemSelectedListener() {
            @Override
            public void onTableItemSelected(GimmickBean gimmickBean, int flag) {
                System.out.println("右键选择整个话术table");
                if (null == gimmickBean) {
                    return;
                }

                if (0 == flag) {          // 删除
                    gimmickMaster.removeGimmick(
                            gimmickBean,
                            new GimmickUI.OnTableItemDeletedListener() {
                                @Override
                                public void onTableItemDeleted(GimmickBean gimmickBean, boolean isContainsInOtherSide) {
                                    if (isContainsInOtherSide) {
                                        gimmickUI.removeGimmickFromOtherSideListView(gimmickBean);
                                    }
                                }
                            });
                } else if (1 == flag) {   // 作为上一条
                    gimmickMaster.addGimmickToOtherSide(
                            gimmickBean,
                            new GimmickUI.OnAddTableItemToOthersideListener() {
                                @Override
                                public void onAddTableItemToOtherside(GimmickBean gimmickBean) {
                                    gimmickUI.addGimmickToOtherSideListView(gimmickBean);
                                }
                            });
                } else if (2 == flag) {   // 再次编辑
                    gimmickUI.editGimmickItem(gimmickBean);
                } else {
                }
            }
        });
    }
}
